package com.starblink.imgsearch.result.ext

import android.graphics.RectF

/**
 * 识图返回String的boxs转rect
 */
internal fun String.box2RectF(): RectF {
    val rectF = RectF()
    try {
        val list = replace("[", "").replace("]", "").split(",").map { it.toFloat() }
        rectF.left = list[0]
        rectF.top = list[1]
        rectF.right = list[2]
        rectF.bottom = list[3]
    } catch(e: NumberFormatException) {
        e.printStackTrace()
    } catch (e: Exception) {
        e.printStackTrace()
    }
    return rectF
}

internal fun RectF.rect2BoxStr(): String {
    return "${this.left.toInt()},${this.top.toInt()},${this.right.toInt()},${this.bottom.toInt()}"
}